﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using MySql.Data.MySqlClient;

namespace TMS
{
    public partial class MyProfileControl : UserControl
    {
        
        public Users User;

        public MyProfileControl()
        {
            Program.GetMainForm.Text = "TMS - Мој профил";
            InitializeComponent();
            User = Program.GetActiveUser;
            
            
        }

        private void MyProfileControl_Load(object sender, EventArgs e)
        {
            UpdateProfile();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            User.UpdateUserDB(NameText.Text, SurnameText.Text, UsernameText.Text);
            UpdateProfile();
            MessageBox.Show("Вашите измени се зачувани");
        }

        public void UpdateProfile()
        {
            User.GetUserFromDB();
            NameText.Text = User.GetName();
            SurnameText.Text = User.GetSurname();
            UsernameText.Text = User.GetUsername();
            EditUsersCheck.Checked = User.EditUseres;
            ViewWarehouseCheck.Checked = User.ViewWarehouse;
            ViewProductsChek.Checked = User.ViewProducts;
            EditProductsCheck.Checked = User.EditProducts;
            ViewProjectCheck.Checked = User.ViewProjects;
            EditProjectCheck.Checked = User.EditProjects;
            EditFinanceCheck.Checked = User.Finance;
        }

        private void btnChanePass_Click(object sender, EventArgs e)
        {
            OldPass.Visible = true;
            OldPassLabel.Visible = true;
            NewPass.Visible = true;
            NewPassLabel.Visible = true;
            ConfirmNewPass.Visible = true;
            ConfirmNewPassLabel.Visible = true;
            btnSavePass.Visible = true;
        }

        private void btnSavePass_Click(object sender, EventArgs e)
        {
            if (OldPass.Text != User.GetPassword())
                MessageBox.Show("Внесовте погрешна Стара Лозинка");
            else if (NewPass.Text != ConfirmNewPass.Text)
                MessageBox.Show("Новата Лозинка не е точно потвредена");
            else
            {
                User.ChangeUserPass(NewPass.Text);
                MessageBox.Show("Вашата Лозинка е успешно променета");
                OldPass.Visible = false;
                OldPassLabel.Visible = false;
                NewPass.Visible = false;
                NewPassLabel.Visible = false;
                ConfirmNewPass.Visible = false;
                ConfirmNewPassLabel.Visible = false;
                btnSavePass.Visible = false;
            }
        }

        private void tabPage2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("kdhsakjd");
        }

 
        private void btnTestMail_Click(object sender, EventArgs e)
        {
            Mail testmail = new Mail();
            testmail.SendForProductOrder(27,32);
        }

        private void btnMyOffres_Click(object sender, EventArgs e)
        {

        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            Program.GetMainForm.registerInHistoryMain(ControlsEnum.WORKORDER_CONTROL, null);

            Program.GetMainForm.ShowControl(ControlsEnum.WORKORDER_CONTROL);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            User.UpdateUserDB(NameText.Text, SurnameText.Text, UsernameText.Text);
            UpdateProfile();

            MessageBox.Show("Вашите измени се зачувани");
        }

 

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            OldPass.Visible = true;
            OldPassLabel.Visible = true;
            NewPass.Visible = true;
            NewPassLabel.Visible = true;
            ConfirmNewPass.Visible = true;
            ConfirmNewPassLabel.Visible = true;
            btnSavePass.Visible = true;
        }

        private void ToStBack_Click(object sender, EventArgs e)
        {
            if (Program.GetMainForm.Back())
            this.Dispose();
        }


        private void ToStForward_Click(object sender, EventArgs e)
        {
            if (Program.GetMainForm.Forward())
            this.Dispose();
        }

        
    }
}
